/**
 * $Id: IndexController.java,v 1.0 2020/7/15 0015 10:08 qiaoyong Exp $
 * <p>
 * Copyright 2018 zonekey Technologies(China),Inc. All rights reserved.
 */
package com.zonekey.freemarkertest.controller;

import com.zonekey.freemarkertest.utils.FreemarkerUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qiaoyong
 * @version $Id: IndexController.java,v 1.1 2020/7/15 0015 10:08 qiaoyong Exp $
 */
@RestController
public class IndexController {
    /**
     * 路由 /index
     * 返回 index 这里默认配置自动映射到 templages/index
     * */
    @RequestMapping("/index")
    public String index() throws Exception{
        Map<String,Object> map=new HashMap<>();
        map.put("data", "[\n" +
                "  {\n" +
                "    \"value\":\"31.45\",\n" +
                "    \"name\":\"读写\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#e7b93c\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"8.13\",\n" +
                "    \"name\":\"举手\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#cd7438\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"31.48\",\n" +
                "    \"name\":\"听讲\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#f1835a\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"9.90\",\n" +
                "    \"name\":\"生生互动\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#d9d552\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"19.04\",\n" +
                "    \"name\":\"应答\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#d33c58\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"2.54\",\n" +
                "    \"name\":\"板书\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#2dabff\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"91.61\",\n" +
                "    \"name\":\"讲授\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#2162c3\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"2.04\",\n" +
                "    \"name\":\"师生互动\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#6c60d5\"\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\":\"3.81\",\n" +
                "    \"name\":\"巡视\",\n" +
                "    \"itemStyle\":{\n" +
                "      \"normal\":{\n" +
                "        \"color\":\"#5ee3e9\"\n" +
                "      }\n" +
                "    }\n" +
                "  }]");
        map.put("data2","{\"coord\":[\"0.3544\",\"0.3038\"],\"fillStyle\":\"#27d3fe\",\"type\":\"混合型\"}");
        String cmtTpl= FreemarkerUtils.getTemplate("new.ftl",map);
        System.out.println(cmtTpl);
        System.out.println(ResourceUtils.getURL("classpath:").getPath());
        System.out.println(ClassUtils.getDefaultClassLoader().getResource("").getPath());
        return "sucess!";
    }

    public List<Map> getDealData() {
        List<Map> list = new ArrayList<>();
        Map<String, Object> first = new HashMap<>();
        first.put("value","31.45");
        first.put("name","读写");
        Map<String, Object> firstIndex = new HashMap<>();
        firstIndex.put("color","#e7b93c");
        first.put("normal", firstIndex);
        list.add(first);
        return list;
    }
}
